package studychinese.model;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.hschinese.pronunciation.R;

import studychinese.activity.LoginActivity;
import studychinese.activity.SettingActivity;
import studychinese.utils.AppUtils;


public class CustomDialog extends Dialog implements View.OnClickListener {
    int layoutRes;// 布局文件
    Context context;
    /** 确定按钮 **/
    private Button confirmBtn;
    /** 取消按钮 **/
    private Button cancelBtn;

    public CustomDialog(Context context) {
        super(context);
        this.context = context;
    }

    /**
     * 自定义布局的构造方法
     *
     * @param context
     * @param resLayout
     */
    public CustomDialog(Context context, int resLayout) {
        super(context);
        this.context = context;
        this.layoutRes = resLayout;
    }

    /**
     * 自定义主题及布局的构造方法
     *
     * @param context
     * @param theme
     * @param resLayout
     */
    public CustomDialog(Context context, int theme, int resLayout) {
        super(context, theme);
        this.context = context;
        this.layoutRes = resLayout;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(layoutRes);

        // 根据id在布局中找到控件对象
        confirmBtn = (Button) findViewById(R.id.back_confirm_btn);
        cancelBtn = (Button) findViewById(R.id.cancel_btn);


        // 为按钮绑定点击事件监听器
        confirmBtn.setOnClickListener(this);
        cancelBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch(v.getId()){
            case R.id.back_confirm_btn:
                AppUtils.changeLogin(context, true);
                Intent intent = new Intent(context, LoginActivity.class);
                intent.putExtra("input","zhengchang");
                context.startActivity(intent);
                AppUtils.changeLogin(context,false);
                ((SettingActivity)context).finish();
                dismiss();

                break;
            case R.id.cancel_btn:
                dismiss();
                break;

        }
    }

}
